﻿using Newtonsoft.Json;
using Rebazza.Server.Entities;
using Rebazza.Server.Interfaces;
using Rebazza.Utils.Enums;

namespace Rebazza.Server.MessageHandlers
{
    public class BaseHandler
    {
        private readonly RoomedHandler roomedHandler;

        public BaseHandler()
        {
            roomedHandler = new RoomedHandler();
        }

        public Message Handle(Message message, IBaseGameServer gameServer, BaseUser user)
        {
            switch (message.Type)
            {
                case CommandType.Roomed:
                    return roomedHandler.Handle(JsonConvert.DeserializeObject<RoomedMessage>(message.Command.ToString()), gameServer, user);
                default:
                    return new Message
                    {
                        Mode = CommandMode.Base,
                        Type = CommandType.Serialize,
                        Command = "Bad command type.",
                        Status = CommandStatus.Error
                    };
            }
        }
    }
}
